package com.platform.modules.wallet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.platform.common.enums.YesOrNoEnum;
import com.platform.common.web.service.impl.BaseServiceImpl;
import com.platform.modules.wallet.dao.WalletNoticeDao;
import com.platform.modules.wallet.domain.WalletNotice;
import com.platform.modules.wallet.service.WalletNoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service("walletNoticeService")
public class WalleNoticeServiceImpl extends BaseServiceImpl<WalletNotice> implements WalletNoticeService {

    @Resource
    private WalletNoticeDao walletNoticeDao;

    @Autowired
    public void setBaseDao() {
        super.setBaseDao(walletNoticeDao);
    }

    @Override
    public WalletNotice getNew() {
        return new WalletNotice().selectOne(new LambdaQueryWrapper<WalletNotice>()
                .eq(WalletNotice::getDeleted, YesOrNoEnum.NO)
                .orderByDesc(WalletNotice::getId));
    }


    @Override
    public WalletNotice getClearNotice() {
        return new WalletNotice().selectOne(new LambdaQueryWrapper<WalletNotice>()
                .eq(WalletNotice::getId, 1)
                .eq(WalletNotice::getDeleted, YesOrNoEnum.NO)
                .orderByDesc(WalletNotice::getId));
    }

    @Override
    public WalletNotice getById(Integer id) {
        WalletNotice walletNotice = new WalletNotice().selectById(id);
        if (YesOrNoEnum.YES.equals(walletNotice.getDeleted())) {
            return null;
        }
        return walletNotice;
    }

    @Override
    public List<WalletNotice> getList() {
        return new WalletNotice().selectList(new LambdaQueryWrapper<WalletNotice>()
                .eq(WalletNotice::getDeleted, YesOrNoEnum.NO));
    }
}
